import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;


public class Webmethods {

	public static void navigateBrowser(WebDriver driver, String data){
		driver.navigate().to(data);
		}

		public static void enterText(WebDriver driver, String xPath, String data){
			driver.findElement(By.xpath(xPath)).clear();
			driver.findElement(By.xpath(xPath)).sendKeys(data);
			}
		public static void enterTextbyid(WebDriver driver, String xPath, String data){
			//driver.findElement(By.id(xPath)).clear();
			driver.findElement(By.id(xPath)).sendKeys(data);
			}
		
		public static String readText(WebDriver driver, String xPath){
			return driver.findElement(By.xpath(xPath)).getText();
			}
		
		public static String verifyText(WebDriver driver, String xPath, String data){
			if (data.equalsIgnoreCase(driver.findElement(By.xpath(xPath)).getText())){
				return "Pass";
			}else {
				return "Fail";
				  }
			}
		public static String verifyTextbyid(WebDriver driver, String xPath, String data){
			if (data.equalsIgnoreCase(driver.findElement(By.id(xPath)).getText())){
				return "Pass";
			}else {
				return "Fail";
				  }
			}
		public static String verifyTextbycss(WebDriver driver, String xPath, String data){
			if (data.equalsIgnoreCase(driver.findElement(By.cssSelector(xPath)).getText())){
				return "Pass";
			}else {
				return "Fail";
				  }
			}
		
		public static void clickElementbyid(WebDriver driver, String xPath){
			driver.findElement(By.id(xPath)).click();
			}
		public static void clickElement(WebDriver driver, String xPath){
			driver.findElement(By.xpath(xPath)).click();
			}
		public static void selectList(WebDriver driver, String xPath, String data){
			Select myDD = new Select(driver.findElement(By.xpath(xPath)));
		    myDD.selectByVisibleText(data);
		    //driver.findElement(By.cssSelector("option[title=\"5 rooms\"]")).click();
		    myDD = null;
			}

		public static void checkCheckbox(WebDriver driver, String xPath){
			if(driver.findElement(By.xpath(xPath)).isSelected()){
				//Do Nothing
			} else {
				driver.findElement(By.xpath(xPath)).click();
				}
			}

		public static void uncheckCheckbox(WebDriver driver, String xPath){
			if(!(driver.findElement(By.xpath(xPath)).isSelected())){
				//Do Nothing
			} else {
				driver.findElement(By.xpath(xPath)).click();
				}
		}
		
		public static void waittime(long time) throws Exception{
				Thread.sleep(time);
				}
			
		}